package cn.rengy.web.framework.sys.sql.web;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.rengy.lang.ResultEntity;
import cn.rengy.web.framework.datagrid.service.DataGridService;

@Controller
@RequestMapping(value = "/authenticated/sys/sql")
public class SysSqlController {
	@Autowired
	private DataGridService dataGridService;
	
	private String sqlname="grid_sys_sql";
	
	@RequiresRoles(value={"developer"})
	@RequestMapping(value="/list",method = RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> list (@RequestBody Map<String,Object> paramMap){
		//Subject subject = SecurityUtils.getSubject();
		//subject.checkRole("admin");
		return dataGridService.query(sqlname, paramMap);
		
	}
	/**
	 * 列表保存
	 * @param sqlid
	 * @param paramMap
	 * @return
	 */
	@RequiresRoles(value={"developer"})
	@RequestMapping(value="/update",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity<?> save(@RequestBody Map<String,Object> paramMap){
		dataGridService.save(sqlname, paramMap);
		return ResultEntity.ok();
	}
}
